import lombok.extern.log4j.Log4j;

import java.sql.Timestamp;
import java.util.concurrent.TimeUnit;

@Log4j
public class WaitTest {

    public static void main(String[] args) throws InterruptedException {
        Object lock = new Object();
        Thread threadA = new Thread(() -> {
            synchronized (lock) {
                System.out.println("A 获取到锁");
                try {
                    System.out.println("休眠一会");
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("调用wait");
                try {
                    System.out.println("调用wait前的线程状态："+Thread.currentThread().getState());
                    System.out.println("当前时间："+System.currentTimeMillis());
                    lock.wait(100);
                    System.out.println("调用notify后的线程状态："+Thread.currentThread().getState());
                    System.out.println("当前时间："+System.currentTimeMillis());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("A 被唤醒");
            }
        }, "A");
        threadA.start();

        Thread threadB = new Thread(() -> {
           synchronized (lock) {
               try {
                   TimeUnit.SECONDS.sleep(2);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
               System.out.println("A 的状态："+threadA.getState());
               while (true) {

               }
           }
        },"B");
        threadB.start();
    }
}